<template>
  <div class="c-bg-sgray c-ph24 c-fs24 c-pt20">
    <div v-for="(item,index) in previewInfo" :key="index">
      <div v-if="item.type == 1" class="tinymce-text c-wb-ba c-contexty-scroll" v-html="item.content"></div>
      <div v-if="item.type == 3" class="c-pt20">
        <aplayer preload="auto" @play="playAplayer" :music="{
          artist:' ',
          title: item.title,
          src: isiOS ? item.audioM3u8 : item.audioM4a,
          pic:none,
        }" :volume="1" repeat="repeat-one" />
      </div>
      <div v-if="item.type == 2" class="c-pt20">
        <div :id='"myVideo" + index' class="c-w100-im" style="height:auto;"></div>
      </div>
    </div>

  </div>
</template>

<script>
import VueAPlayer from "@/plugin/vue-aplayer/vue-aplayer.vue";
import { utilJs } from "@/utils/common.js";
import { getXgplayer } from "@/utils/xgplayerJs.js";
//const clientW = document.documentElement.clientWidth > 640 ? 640 - 48 : document.documentElement.clientWidth - 48; //屏幕宽度
//const videoH = clientW / 320 * 180; //视频高度
let curHwId = ''; //当前作业ID
export default {
  name: "HomeWorkPreview",
  components: {
    Aplayer: VueAPlayer
  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : "mb5_default",
      isiOS: false,
      previewInfo: [],
    };
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  methods: {
    playAplayer(src) {
      if (typeof src == 'string') {
        let arr = document.getElementsByTagName("video");
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].src !== src) {
            arr[i].pause();
          }
        }
      }
    },
    //获取结果信息
    getAnwerResultInfo() {
      utilJs.getMethod(
        global.apiurl + "signCard/preview/" + curHwId,
        res => {
          this.previewInfo = res.description;
          for (let i = 0; i < res.description.length; i++) {
            if (res.description[i].type == 2) {
              setTimeout(() => {
                let videoObj = {
                  videoMp4: res.description[i].content,
                  videoM3U8: res.description[i].content,
                  autoplay: false,
                  fluid: false,
                  isCssFullScreen: true,
                  poster: 'https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/assets/i/wap/clockIn/video-bg2.png',
                }
                let dId = 'myVideo' + i;
                getXgplayer(dId, videoObj);
              }, 300);
            }
          }
        }
      );
    },

    //分享
    wechatShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShareInfo") ? JSON.parse(localStorage.getItem("homeWorkShareInfo")) : shareIndexData;
      utilJs.wechatConfig(
        shareData.shareUrl,
        shareData.title,
        shareData.shareImg,
        shareData.shareDesc,
        function () { },
        true
      );
    },
    //手机端分享
    appShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShareInfo") ? JSON.parse(localStorage.getItem("homeWorkShareInfo")) : shareIndexData;
      utilJs.appShareTrue(
        shareData.title,
        shareData.shareImg,
        shareData.shareUrl,
        shareData.shareDesc
      );
    }
  },
  activated() {
    setDocumentTitle("课程预览");// eslint-disable-line
    curHwId = this.$route.query.curHwId;
    this.isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    this.examInfo = {};
    this.answerSheet = []
    this.getAnwerResultInfo();
    this.wechatShare();
  },
  deactivated() { }
};
</script>